﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ERP_RORZE_SYSTEM;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class panel_LocalTroubleReport : UserControl
    {
        private INISettings mySetting;
        private SqlConnection myConnection;

        public panel_LocalTroubleReport()
        {
            InitializeComponent();            

            this.mySetting = new INISettings();
            this.myConnection = new SqlConnection(mySetting.SQLConnectionString);
            this.subGroup.SelectedIndex = 0;
            this.yearText.Text = DateTime.Now.Year.ToString();
        }

        private void buttonView_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.yearText.Text.Trim()))
            {
                MessageBox.Show("Please enter Year to view report");
            }
            else
            {
                switch (this.subGroup.SelectedIndex)
                {
                    case 0:
                        reportDocument.DocumentSource = null;
                        rpt_F4LocalTrouble F4LocalTrouble = new rpt_F4LocalTrouble();
                        F4LocalTrouble.year = this.yearText.Text.Trim();
                        double plan_check = 0;
                        if (double.TryParse(this.planValue.Text.Trim(), out plan_check))
                        {
                            F4LocalTrouble.plan = this.planValue.Text.Trim();
                            F4LocalTrouble.LoadData();
                            F4LocalTrouble.CreateDocument();
                            reportDocument.DocumentSource = F4LocalTrouble;
                        }
                        else
                        {
                            MessageBox.Show("Invalid Plan");
                        }
                        break;                        
                    case 1:
                        reportDocument.DocumentSource = null;
                        rpt_F5LocalTrouble F5LocalTrouble = new rpt_F5LocalTrouble();
                        F5LocalTrouble.year = this.yearText.Text.Trim();
                        double plan_check2 = 0;
                        if (double.TryParse(this.planValue.Text.Trim(), out plan_check2))
                        {
                            F5LocalTrouble.plan = this.planValue.Text.Trim();
                            F5LocalTrouble.LoadData();
                            F5LocalTrouble.CreateDocument();
                            reportDocument.DocumentSource = F5LocalTrouble;
                        }
                        else
                        {
                            MessageBox.Show("Invalid Plan");
                        }
                        break;                    
                }                
            }  
        }
    }
}
